#ifndef _FLASH_MELCEP_H_
#define _FLASH_MELCEP_H_

#include "pstorage.h"
#include <stdbool.h>
#include "app_scheduler.h"

struct flash_melcep_parm_t
{
    uint8_t num;
    uint8_t *buf;
    uint16_t length;
    uint16_t offset;
};

typedef enum {
    FLASH_MELCEP_STATUS_WRITE_START,
    FLASH_MELCEP_STATUS_WRITE_END,
    FLASH_MELCEP_STATUS_READ_START,
    FLASH_MELCEP_STATUS_READ_END,
}FLASH_MELCEP_STATUS;

// 根据CONFIG_AUDIO_FRAME_SIZE_SAMPLES配置，方便写入
#define FLASH_MELCEP_BLOCK_SIZE        4096
// 4个语音库指令，一个唤醒语音库指令，一个待识别的语音
#define FLASH_MELCEP_BLOCK_NUM         6

typedef void (*flash_melcep_status_cb)(FLASH_MELCEP_STATUS status);
typedef void (*flash_melcep_eraser_finish_fun_t)(uint8_t num);

#if defined (__CC_ARM )
#define ADDR_ALIGNED_4 __attribute__ ((aligned (4)))
#endif

extern uint32_t flash_melcep_init(bool is_init_pstorage);
extern uint32_t flash_melcep_write(uint32_t block_num,uint8_t *buf,uint32_t length,uint32_t offset);
extern uint32_t flash_melcep_read(uint32_t block_num,uint8_t *buf,uint32_t length,uint32_t offset);
extern void flash_melcep_get_err_info(uint16_t *read_err,uint16_t *write_err);
extern uint32_t flash_melcep_status_evt_reg(flash_melcep_status_cb func);
extern uint32_t flash_melcep_clear(uint32_t block_num,uint32_t block_cnt);
extern uint32_t flash_melcep_store(uint32_t block_num,uint8_t *buf,uint32_t length,uint32_t offset);
extern uint32_t flash_melcep_get_startADD(void);
extern bool flash_melcep_eraser_finish_reg(flash_melcep_eraser_finish_fun_t fun);

#endif // _FLASH_MELCEP_H_
